#ifndef STM32F1_SPI_H_
#define STM32F1_SPI_H_

#include "iodef.h"

typedef struct
{
        __IO uint16_t CR1;
        uint16_t  RESERVED0;
        __IO uint16_t CR2;
        uint16_t  RESERVED1;
        __IO uint16_t SR;
        uint16_t  RESERVED2;
        __IO uint16_t DR;
        uint16_t  RESERVED3;
        __IO uint16_t CRCPR;
        uint16_t  RESERVED4;
        __IO uint16_t RXCRCR;
        uint16_t  RESERVED5;
        __IO uint16_t TXCRCR;
        uint16_t  RESERVED6;
        __IO uint16_t I2SCFGR;
        uint16_t  RESERVED7;
        __IO uint16_t I2SPR;
        uint16_t  RESERVED8;
}spi_reg_t;

#define SPI_CR1_CPHA            _BIT(0)
#define SPI_CR1_CPOL            _BIT(1)
#define SPI_CR1_MSTR            _BIT(2)
#define SPI_CR1_BR_MASK         _VALUE(3, 0x7)
#define SPI_CR1_BR(n)           _VALUE(3, (n))
#define SPI_CR1_SPE             _BIT(6)
#define SPI_CR1_LSBFIRST        _BIT(7)
#define SPI_CR1_SSI             _BIT(8)
#define SPI_CR1_SSM             _BIT(9)
#define SPI_CR1_RXONLY          _BIT(10)
#define SPI_CR1_DFF             _BIT(11)
#define SPI_CR1_CRCNEXT         _BIT(12)
#define SPI_CR1_CRCEN           _BIT(13)
#define SPI_CR1_BIDIOE          _BIT(14)
#define SPI_CR1_BIDIMODE        _BIT(15)

#define SPI_CR2_RXDMAEN         _BIT(0)
#define SPI_CR2_TXDMAEN         _BIT(1)
#define SPI_CR2_SSOE            _BIT(2)
#define SPI_CR2_ERRIE           _BIT(5)
#define SPI_CR2_RXNEIE          _BIT(6)
#define SPI_CR2_TXEIE           _BIT(7)

#define SPI_SR_RXNE             _BIT(0)
#define SPI_SR_TXE              _BIT(1)
#define SPI_SR_CHSIDE           _BIT(2)
#define SPI_SR_UDR              _BIT(3)
#define SPI_SR_CRCERR           _BIT(4)
#define SPI_SR_MODF             _BIT(5)
#define SPI_SR_OVR              _BIT(6)
#define SPI_SR_BSY              _BIT(7)

#endif /* STM32F1_SPI_H_ */
